package org.example.communication_room.utils;

/**
 * API返回体标准化
 *
 * @param <T> the type of data included in the response if any
 */
public class ApiResponse<T> {
    private int status;
    private String message;
    private T data;
    private boolean success;

    /**
     * Constructor for ApiResponse.
     *
     * @param status the HTTP status code
     * @param message the message describing the response
     * @param data the data to be included in the response
     * @param success flag indicating if the response denotes a successful operation
     */
    public ApiResponse(int status, String message, T data, boolean success) {
        this.status = status;
        this.message = message;
        this.data = data;
        this.success = success;
    }

    // Getters and setters
    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    // Static factory methods
    public static <T> ApiResponse<T> success(T data) {
        return new ApiResponse<>(200, "Success", data, true);
    }

    public static <T> ApiResponse<T> success(String message, T data) {
        return new ApiResponse<>(200, message, data, true);
    }

    public static <T> ApiResponse<T> error(int status, String message) {
        return new ApiResponse<>(status, message, null, false);
    }

    // Additional helper methods for common responses
    public static <T> ApiResponse<T> notFound(String message) {
        return new ApiResponse<>(404, message, null, false);
    }

    public static <T> ApiResponse<T> forbidden(String message) {
        return new ApiResponse<>(403, message, null, false);
    }
}
